package com.eddie.factory.simplefactory.pizzastore.order;

import com.eddie.factory.constant.PizzaConstant;
import com.eddie.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.eddie.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.eddie.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.eddie.factory.simplefactory.pizzastore.pizza.Pizza;

/**
 * @author Eddie
 * @date 2022/4/29 11:48
 */
public class SimpleFactory {


    private SimpleFactory() {

    }

    private static class SimpleFactoryInstance{
        private static final SimpleFactory INSTANCE = new SimpleFactory();
    }

    public static SimpleFactory getInstance() {
        return SimpleFactoryInstance.INSTANCE;
    }

    /**
     * 根据orderType返回对应的Pizza对象
     * @param orderType
     * @return
     */
    public Pizza createPizza(String orderType) {
        Pizza pizza = null;
        System.out.println("使用简单工厂模式");
        if(PizzaConstant.GREEK_NAME.equals(orderType)) {
            pizza=  new GreekPizza();
            pizza.setName("希腊披萨");
        }else if(PizzaConstant.CHEESE_NAME.equals(orderType)) {
            pizza = new CheesePizza();
            pizza.setName("奶酪披萨");
        }else if (PizzaConstant.PEPPER_NAME.equals(orderType)){
            pizza = new PepperPizza();
            pizza.setName("胡椒披萨");
        }
        return pizza;
    }


}
